<template>
	<view class="container">
		<!-- web-view 组件：src 为要打开的网页地址 -->
		<web-view :src="webUrl" @message="messageTest"></web-view>
	</view>
</template>

<script>
	import config from '@/config/api.js'
	import storage from "@/utils/storage.js"; //缓存
	import {
		renderContract
	} from '@/api/order.js'
	export default {
		data() {
			return {
				type: '',
				sn: '',
				status: '',
				webUrl: '' // 网页地址（从跳转参数中获取）
			};
		},
		onLoad(options) {
			// 接收跳转时传递的网页地址（从 options 中获取）
			if (options.type) {
				this.type = options.type
			}

			if (options.url) {
				this.webUrl = decodeURIComponent(options.url);
			}
			if (options.sn) {
				this.sn = options.sn
			}
			if (options.status) {
				this.status = options.status
			}
			// this.webUrl = `https://gjweb.laosijijiaxiao.com/pages/h5/h5?sn=174`;
			this.toHtml()
		},
		methods: {
			toHtml() {
				const s = storage.getAccessToken();
				if (this.type == 'PRIVACY_POLICY') {
					uni.setNavigationBarTitle({
						title: "隐私协议",
					});
					this.webUrl = `${config.h5}/static/html/privacy-policy.html`;
				}
				if (this.type == 'USER_AGREEMENT') {
					uni.setNavigationBarTitle({
						title: "用户协议",
					});
					this.webUrl = `${config.h5}/static/html/user-agreement.html`;
				}
				if (this.type === 'READ_FILE') {
					uni.setNavigationBarTitle({
						title: "用户租赁及服务协议",
					});
					this.webUrl =
						`${config.h5}/static/html/docxfile.html?url=${encodeURIComponent(config.img)}&s=${s}&sn=${this.sn}&status=${this.status}`;
				}
			},
			messageTest(e) {
				console.log('e.detail------', e)
				if (e.detail.type == 'back') {
					uni.redirectTo({
						url: `/pages/order/orderDetail?sn=${e.detail.sn}`
					})
				}
				if (e.detail.type == 'sign') {
					uni.redirectTo({
						url: `/pages/order/signSuccess?sn=${e.detail.sn}`
					})
				}
			}
		}
	};
</script>

<style>
	.container {
		width: 100%;
		height: 100%;
	}
</style>